﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;

namespace PxWindowsSysinfo
{
    class CPUInfo
    {
        string[] ayCPUArchitecture = new string[5];

        public void Init()
        {
            ayCPUArchitecture[0] = "x86";
            ayCPUArchitecture[1] = "MIPS";
            ayCPUArchitecture[2] = "Alpha";
            ayCPUArchitecture[3] = "PowerPC";
            ayCPUArchitecture[6] = "ia64";
            ayCPUArchitecture[9] = "x64";
        }

        public string GetCPUInfo()
        {
            string strCPUInfo = "======================\nCPU Info : \n";

            string strInfoKey = "Win32_Processor";
            ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM " + strInfoKey);

            Console.WriteLine(strInfoKey + " total count : " + s.Get().Count);
            foreach (ManagementObject service in s.Get())
            {
                // show the instance
                strCPUInfo += "Caption : " + service["Caption"] + "\n";
                strCPUInfo += "Name : " + service["Name"] + "\n";
                strCPUInfo += "Architecture : " + ayCPUArchitecture[service["Architecture"]] + "\n";
                //UInt64 nSize = UInt64.Parse(service["Size"].ToString());
                //Console.WriteLine((nSize/1024/1024).ToString() + "MB");
                strCPUInfo += "ProcessorId : " + service["ProcessorId"] + "\n";
                strCPUInfo += "SerialNumber : " + service["SerialNumber"] + "\n";
                strCPUInfo += "UniqueId : " + service["UniqueId"] + "\n";
                strCPUInfo += "ThreadCount : " + service["ThreadCount"] + "\n";
                strCPUInfo += "NumberOfCores : " + service["NumberOfCores"] + "\n";
                strCPUInfo += "CurrentClockSpeed : " + service["CurrentClockSpeed"] + " MHz\n";
                strCPUInfo += "MaxClockSpeed : " + service["MaxClockSpeed"] + " MHz\n\n";
            }

            strCPUInfo += "======================\n";
            return strCPUInfo;
        }
    }
}
